package com.hy.mvc.biz.service.manager;

import com.hy.mvc.biz.service.manager.base.PageManager;
import com.hy.mvc.biz.service.mapper.UUserDOMapper;
import com.hy.mvc.domain.dataobject.UUserDO;
import com.hy.mvc.domain.dataobject.UUserDOExample;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <pre>
 *    author  : Booker
 *    time    : 2017/12/6 14:53
 *    desc    : 输入描述
 *    version : v1.0
 * </pre>
 */
@Component
public class UUserDOManager extends PageManager<UUserDO, UUserDOExample, UUserDOMapper> {

    public int saveOrUpdate(UUserDO uUserDO) {
        UUserDO temp = findById(uUserDO.getId());
        if (null == temp) {
            return mapper.insert(uUserDO);
        }
        uUserDO.setId(temp.getId());
        return mapper.updateByPrimaryKeySelective(uUserDO);
    }

    public UUserDO findById(Long id) {
        UUserDOExample example = new UUserDOExample();
        example.createCriteria().andIdEqualTo(id);
        List<UUserDO> list = mapper.selectByExample(example);
        return list.size() > 0 ? list.get(0) : null;
    }

    public List<UUserDO> findAllValidUUserDO() {
        UUserDOExample example = new UUserDOExample();
        example.createCriteria().andIdIsNotNull();
//        example.createCriteria().andv(true);
        return mapper.selectByExample(example);

    }

    public UUserDO findByName(String name) {
        UUserDOExample example = new UUserDOExample();
        example.createCriteria().andNameEqualTo(name);
        List<UUserDO> list = mapper.selectByExample(example);
        return list.size() > 0 ? list.get(0) : null;
    }

    public int getDataCount(UUserDOExample example) {
        return mapper.countByExample(example);
    }
}
